<?php
header("Content-type: application/json");

require_once(__DIR__ . "/C5Request.php");
require_once(__DIR__ . "/C5Sessions.php");

$action = get("action");

$object = "";
if ($action == "get_session") {
    $object = C5Sessions::get_session(get("name"));
}
if ($action == "set_session") {
    C5Sessions::set_session(get("name"), get("value"));
}
if ($action == "remove_session") {
    C5Sessions::remove_session(get("name"));
}
if ($action == "set_json_object") {
    $name = get("name");
    $string = get("value");
    $matrix = json_decode($string, true);
    C5Sessions::set_session($name, $matrix);
}

if (is_object($object) || is_array($object)) {
    print json_encode($object);
} else {
    print $object;
}

